package com.cuitrip.business.home.travel.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 排序筛选对象
 * Created by sheena on 16/1/7.
 */
public class FilterExp implements Serializable {

    public static SortInfo DEFAULT_SORT_KEY = new SortInfo("service_default_rank", "");

    private int selectSortPosition = -1;

    /**
     * 目的地筛选
     */
    private ArrayList<Destination> destExp = new ArrayList();

    /**
     * 筛选的对象
     */
    private ArrayList<FilterInfo> filterExp = new ArrayList();


    /**
     * 排序对象
     */
    private ArrayList<SortInfo> sortExp = new ArrayList();

    public static SortInfo getDefaultSort() {
        if (DEFAULT_SORT_KEY == null) {
            DEFAULT_SORT_KEY = new SortInfo("service_default_rank", "");
        }
        return DEFAULT_SORT_KEY;
    }

    public int getSelectSortPosition() {
        return selectSortPosition;
    }

    public void setSelectSortPosition(int selectSortPosition) {
        this.selectSortPosition = selectSortPosition;
    }

    public ArrayList<SortInfo> getSortExp() {
        return sortExp;
    }

    public void setSortExp(ArrayList<SortInfo> sortExp) {
        this.sortExp = sortExp;
    }

    public int getSortListSize() {
        return sortExp.size();
    }

    public SortInfo getSort(int position) {
        return sortExp.get(position);
    }

    public SortInfo getSelectSort() {
        if (selectSortPosition < 0) {
            return getDefaultSort();
        } else {
            return sortExp.get(selectSortPosition);
        }
    }

    public SortInfo getLikeDescSort() {
        return new SortInfo("-like", "");
    }

    public ArrayList<FilterInfo> getFilterExp() {
        return filterExp;
    }

    public void setFilterExp(ArrayList<FilterInfo> filterExp) {
        this.filterExp = filterExp;
    }

    public ArrayList<Destination> getDestExp() {
        return destExp;
    }

    public void setDestExp(ArrayList<Destination> destExp) {
        this.destExp = destExp;
    }

    public List<String> getSelectedCityAbbr() {
        List<String> valueList = new ArrayList<>();
        for (Destination destination : destExp) {
            List<Destination.Value> destinationValueList = destination.getList();
            for (Destination.Value value : destinationValueList) {
                if (value.isSelected()) {
                    valueList.add(value.getAbbr());
                }
            }
        }
        return valueList;
    }

    public static class SortInfo implements Serializable {

        /**
         * 排序的key
         */
        private String searchKey;
        /**
         * 排序的名称
         */
        private String desc;

        public SortInfo() {
        }

        public SortInfo(String searchKey, String desc) {
            this.searchKey = searchKey;
            this.desc = desc;
        }

        public String getSearchKey() {
            return searchKey;
        }

        public void setSearchKey(String searchKey) {
            this.searchKey = searchKey;
        }

        public String getDesc() {
            return desc;
        }

        public void setDesc(String desc) {
            this.desc = desc;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (o == null || getClass() != o.getClass()) {
                return false;
            }
            SortInfo that = (SortInfo) o;
            if (searchKey == null) {
                return false;
            } else {
                return searchKey.equals(that.searchKey);
            }
        }

    }

}
